package com.pt25.base.res;

import lombok.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
@Builder
public class ResBody {
    /**
     * 返回的消息
     */
    private String msg;
    /**
     * 状态吗，build操作时默认值生效
     */
    @Builder.Default
    private Integer code = 0;
    /**
     * 返回的数据
     */
    private Object data;

    public ResBody ok() {
        this.setMsg(ResCode.OK.getMsg());
        this.setCode(ResCode.OK.getCode());
        return this;
    }

    public ResBody ok(Object data) {
        ResBody ok = ok();
        ok.setData(data);
        return ok;
    }

    public ResBody fail() {
        this.setMsg(ResCode.FAIL.getMsg());
        this.setCode(ResCode.FAIL.getCode());
        return this;
    }

    public ResBody fail(String msg) {
        this.setMsg(msg);
        this.setCode(ResCode.FAIL.getCode());
        return this;
    }
}
